package com.ry.novel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ry.novel.model.dto.UserInfo;
import com.ry.novel.model.dto.condition.UserQuery;
import com.ry.novel.model.entity.User;
import com.ry.novel.model.resp.Result;
import com.ry.novel.service.ReaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ry
 * @since 2022-04-03 16:20
 **/
@RequestMapping("/reader")
@RestController
public class ReaderController {
    @Autowired
    private ReaderService readerService;

    @PostMapping("/queryReader")
    public Result<Page<UserInfo>> queryReader(@RequestBody UserQuery userQuery){
        Page<UserInfo> infoPage = readerService.queryReader(userQuery);


        return Result.ok(infoPage);
    }

    @PostMapping("/deleteReader")
    public Result<Void> deleteReader(@RequestParam("id")Long id){
        readerService.deleteReader(id);

        return Result.ok();
    }

    @PostMapping("/addReader")
    public Result<Void> addReader(@RequestBody UserInfo reader){
        readerService.addReader(reader);

        return Result.ok();
    }

    @PostMapping("/updateReader")
    public Result<Void> updateReader(@RequestBody UserInfo reader){
        readerService.updateReader(reader);

        return Result.ok();
    }

    @GetMapping("/queryNotAuthor")
    public Result<List<UserInfo>> queryNotAuthor(){
        return Result.ok(readerService.queryNotAuthor());
    }

    @PostMapping("/queryAllReader")
    public Result<List<UserInfo>> queryAllReader(){
        List<UserInfo> userInfos = readerService.queryAll();

        return Result.ok(userInfos);
    }
}
